package com.baidu.ota.utils;

import java.lang.reflect.Method;

/**
 * 获取系统Build.prop中字段的值
 */
public class SystemPropUtil {

    public static String get(String systemField, String defVal) {
        try {
            Class cls = Class.forName("android.os.SystemProperties");
            Method method = cls.getMethod("get", String.class, String.class);
            method.setAccessible(true);
            return (String) method.invoke(null, systemField, defVal);
        } catch (
                Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static boolean set(String key, String val) {
        try {
            Class cls = Class.forName("android.os.SystemProperties");
            Method method = cls.getMethod("set", String.class, String.class);
            method.setAccessible(true);
            method.invoke(null, key, val);

            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
